<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="发送方式" class="myform-item">
          <el-select
            v-model="form.type"
            placeholder="请选择"
            @change="onSelectSend"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="快递单号"
          v-if="form.type == 1"
          class="myform-item"
        >
          <el-input
            v-model="form.courier_number"
            placeholder="请输入快递单号"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="加工厂" class="myform-item">
          <el-select v-model="form.factory_name" placeholder="请选择">
            <el-option label="全部" value=""> </el-option>
            <el-option
              v-for="item in FactoryList"
              :key="item.id"
              :label="item.factory_name"
              :value="item.factory_name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送状态" class="myform-item">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option
              v-for="item in optionsStatus"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发送时间" class="myform-item">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="form.fa_time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="发送人" align="center" prop="cname">
      </el-table-column>
      <el-table-column label="发送方式" align="center" prop="type">
        <template slot-scope="{ row }">
          {{ row.type == 1 ? "快递发送" : "当面提取" }}
        </template>
      </el-table-column>
      <el-table-column label="快递单号" align="center" prop="courier_number">
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="list">
        <template slot-scope="{ row }">
          <div>
            <div v-for="(item, index) in row.list" :key="index">
              {{ item.sku_code }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="发送时间" align="center" prop="fa_time">
      </el-table-column>
      <el-table-column label="加工厂" align="center" prop="factory_name">
      </el-table-column>
      <el-table-column label="发送状态" align="center" prop="status">
        <template slot-scope="{ row }">
          <div :style="{ color: row.m_status != 0 ? '#2c70d6' : '' }">
            {{
              row.status == 1 ? "已发送" : row.status == 2 ? "已签收" : "已确认"
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="总数量" align="center" prop="num">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onLook(row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminCodeGetsendRfidlist"
    />
    <el-dialog
      title="发送详情"
      :visible.sync="dialogVisible"
      width="40%"
      :close-on-click-modal="false"
    >
      <div>
        <div class="dialogVisibleTop">
          <div v-if="row.type == 1">快递单号：{{ row.courier_number }}</div>
          <div v-else>当面提取</div>
          <div>加工厂：{{ row.factory_name }}</div>
          <div>
            发送状态：{{
              row.status == 1 ? "已发送" : row.status == 2 ? "已签收" : "已确认"
            }}
          </div>
          <div>总数量：{{ row.num }}</div>
        </div>
        <el-table :data="row.list" style="width: 100%" border>
          <el-table-column
            label="生产加工单号"
            align="center"
            prop="processing_code"
          >
          </el-table-column>
          <el-table-column label="SKU编码" align="center" prop="sku_code">
          </el-table-column>
          <el-table-column label="数量" align="center" prop="num">
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { postAdminCodeGetsendRfidlist, postHomeCodeGetFactory } from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      form: {
        type: "",
        courier_number: "",
        factory_name: "",
        status: 0,
        fa_time: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
      row: "",
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "1",
          label: "快递发送",
        },
        {
          value: "2",
          label: "当面提取",
        },
      ],
      FactoryList: [],
      optionsStatus: [
        {
          value: 0,
          label: "全部",
        },
        {
          value: 1,
          label: "已发送",
        },
        {
          value: 2,
          label: "已签收",
        },
        {
          value: "3",
          label: "已确认",
        },
      ],
    };
  },
  activated() {
    let form = this.form;
    this.postHomeCodeGetFactory();
    this.postAdminCodeGetsendRfidlist(form);
  },
  methods: {
    onSelectSend(e) {
      console.log("e------------------------>", e);
      if (e != 1) {
        this.form.courier_number = "";
      }
    },
    // 查看
    onLook(row) {
      this.row = row;
      this.dialogVisible = true;
    },
    // 加工厂列表
    postHomeCodeGetFactory() {
      let obj = {
        page: 1,
        size: 10000,
        factory_name: "",
        type: 0,
      };
      postHomeCodeGetFactory(obj).then((res) => {
        console.log("加工厂列表", res);
        this.FactoryList = res.data;
      });
    },
    // qc列表
    async postAdminCodeGetsendRfidlist(data) {
      this.loading = true;
      this.form = data;
      let form = JSON.parse(JSON.stringify(this.form));
      if (form.fa_time) {
        form.fa_time = `${form.fa_time[0]}/${form.fa_time[1]}`;
      }
      postAdminCodeGetsendRfidlist(form)
        .then((res) => {
          this.loading = false;
          console.log("qc列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminCodeGetsendRfidlist(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.dialogVisibleTop {
  display: flex;
  padding-bottom: 30px;
  > div {
    margin-right: 30px;
  }
}
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
